<template>
  <header class="header">
    <h1>todos</h1>
    <input
      v-model.trim="inputVal"
      @keyup.enter="addEvent"
      class="new-todo"
      placeholder="请输入任务名称"
      autofocus
    />
  </header>
</template>
<script>
export default {
  data () {
    return {
      inputVal: ''
    }
  },
  methods: {
    addEvent () {
      if (this.inputVal !== '') {
        this.$emit('add', {
          id: Date.now(),
          name: this.inputVal,
          isDone: false
        })
        this.inputVal = ''
        console.log(this.inputVal)
      }
    }
  }
}
</script>
<style></style>
